package ca.llsutherland.squash.domain.helper;

import ca.llsutherland.squash.domain.DomainObject;
import ca.llsutherland.squash.exceptions.ValidationException;
import ca.llsutherland.squash.utils.ErrorConstants;
import ca.llsutherland.squash.utils.StringUtils;

public class DomainObjectHelper {

    protected static void assertValidId(Long id) throws ValidationException {
        if(id == null) {
            throw new ValidationException(ErrorConstants.NULL_ID_ERROR);
        }
    }

    protected static void assertNonBlankStringWithErrorMessage(String name, String errorToDisplay) {
        if(StringUtils.isBlankString(name)) {
            throw new ValidationException(errorToDisplay);
        }
    }
    
    protected static void assertInvalidStringWithErrorMessage(String name, String errorToDisplay) {
        if(StringUtils.containsInvalidCharacters(name)) {
            throw new ValidationException(errorToDisplay);
        }
    }

    public static void assertNotNullWithErrorMessage(DomainObject domainObject, String errorToDisplay) {
        if(domainObject == null) {
            throw new ValidationException(errorToDisplay);
        }
    }
}
